import {ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {NativeService} from '../../services/native.service';
import {StorageService} from '../../services/storage.service';
import {Utils} from '../../services/Utils';

@Component({
  selector: 'app-filter-time',
  templateUrl: './filter-time.component.html',
  styleUrls: ['./filter-time.component.scss'],
})
export class FilterTimeComponent implements OnInit {
  @Output()
  getTimeDate = new EventEmitter<any>();
  beginTime = '';
  endTime = '';
  dateTimeMin: string; // 最小时间;
  begin;
  end;
  searchName = '';
  constructor(private  native: NativeService, private cd: ChangeDetectorRef,
              private storage: StorageService) {
    this.dateTimeMin = Utils.dateFormat(new Date(), 'YYYY-MM-DD');
  }

  ngOnInit() {
  }
  // 确认
  onSubmit() {
    console.log(this.beginTime);
    console.log(this.endTime);
    if (this.beginTime && this.endTime && this.beginTime.slice(0, 10) > this.endTime.slice(0, 10)) {
      this.native.showAlert('起始日期不能大于结束日期')
    } else {
      if (this.beginTime == '') {
        this.begin = '';
      } else {
        this.begin = this.beginTime.slice(0, 10);
      }
      if (this.endTime == '') {
        this.end = '';
      } else {
        this.end = this.endTime.slice(0, 10);
      }
      const param = {
        beginTime: this.begin,
        endTime:  this.end,
        searchName: this.searchName,
      };
      console.log(param);
      this.getTimeDate.emit(param);
      this.cd.detectChanges();
    }
  }

  ionViewWillLeave() {
    this.cd.detach();
  }

  onTouchMove(e) {
    e.preventDefault();
    this.cd.detectChanges();
  }
}
